home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / imc9104.zip / TESTFUNC.C < prev    next >
Text File  |  1991-03-05  |  3KB  |  123 lines

  1. /*******************************************************************
  2. * TESTFUNC.C - This file contains all of the test functions used   *
  3. * in the accompanying optimization article in IMC April 1991.      *
  4. *                                                                  *
  5. * There are 4 sets of functions, a through d. By uncommenting one  *
  6. * of the #define statements below you can choose which set of test *
  7. * functions to run. For example, to test testfunc1c() and          *
  8. * testfunc2c(), you would uncomment the line: "#define TEST_C   0" *
  9. *******************************************************************/
  10.  
  11. //#define TEST_A    0
  12. //#define TEST_B    0
  13. //#define TEST_C    0
  14. //#define TEST_D    0
  15.  
  16. /*******************************************************************
  17. * These statements generate macros based on the uncommented line   *
  18. * from above.                                                      *
  19. *******************************************************************/
  20. #ifdef TEST_A
  21. #define testfunc1a(v) testfunc1(v)
  22. #define testfunc2a(v) testfunc2(v)
  23. #endif
  24.  
  25. #ifdef TEST_B
  26. #define testfunc1b(v) testfunc1(v)
  27. #define testfunc2b(v) testfunc2(v)
  28. #endif
  29.  
  30. #ifdef TEST_C
  31. #define testfunc1c(v) testfunc1(v)
  32. #define testfunc2c(v) testfunc2(v)
  33. #endif
  34.  
  35. #ifdef TEST_D
  36. #define testfunc1d(v) testfunc1(v)
  37. #define testfunc2d(v) testfunc2(v)
  38. #endif
  39.  
  40. /*******************************************************************
  41. * These variables are used by several of the test functions.       *
  42. *******************************************************************/
  43. int w, x, y=1, z=3, a=5, b=7, c=11, d=13;
  44.  
  45. /*******************************************************************
  46. * This empty function is used to determine the standard function   *
  47. * call overhead.                                                   *
  48. *******************************************************************/
  49. void emptyfunc(void)
  50.     {
  51.     }
  52.  
  53. /*******************************************************************
  54. * The first set of test functions discussed in the article.        *
  55. *******************************************************************/
  56. void testfunc1a(void)
  57.     {
  58.     _asm
  59.         {
  60.         add WORD PTR x,0;
  61.         }
  62.     }
  63.  
  64. void testfunc2a(void)
  65.     {
  66.     x = x + 0;
  67.     }
  68.  
  69. /*******************************************************************
  70. * The second set of test functions discussed in the article.       *
  71. *******************************************************************/
  72. void testfunc1b(void)
  73.     {
  74.     _asm
  75.         {
  76.         mov al, 2;
  77.         imul WORD PTR x;
  78.         mov WORD PTR x, ax;
  79.         }
  80.     }
  81.  
  82. void testfunc2b(void)
  83.     {
  84.     x <<= 1;
  85.     }
  86.  
  87. /*******************************************************************
  88. * The third set of test functions discussed in the article.        *
  89. *******************************************************************/
  90. void testfunc1c(void)
  91.     {
  92.     x = y + ((a * b) - 1);
  93.     z = ((a * b) - 1) / c;
  94.     }
  95.  
  96. void testfunc2c(void)
  97.     {
  98.     register int t = (a * b) - 1;
  99.  
  100.     x = y + t;
  101.     z = t / c;
  102.     }
  103.  
  104. /*******************************************************************
  105. * The fourth set of test functions discussed in the article.       *
  106. *******************************************************************/
  107. void testfunc1d(void)
  108.     {
  109.     x = y + ((a * b) - 1);
  110.     z = ((a * b) - 1) / c;
  111.     w = ((a * b) - 1) * d;
  112.     }
  113.  
  114. void testfunc2d(void)
  115.     {
  116.     register int t = (a * b) - 1;
  117.  
  118.     x = y + t;
  119.     z = t / c;
  120.     w = t * d;
  121.     }
  122.  
  123.